<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仪表盘 - Modbus监控系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
        }

        .header {
            background: white;
            padding: 20px 30px;
            border-radius: 10px;
            margin-bottom: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .header h1 {
            font-size: 24px;
            color: #333;
        }

        .device-selector {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .device-selector select {
            padding: 8px 15px;
            font-size: 16px;
            border: 2px solid #3b82f6;
            border-radius: 5px;
            background: white;
            cursor: pointer;
        }

        .status-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #10b981;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {

            0%,
            100% {
                opacity: 1;
            }

            50% {
                opacity: 0.5;
            }
        }

        .cards-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
            margin-bottom: 20px;
        }

        .data-card {
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            text-align: center;
            transition: transform 0.3s;
            border-left: 4px solid #ddd;
        }

        .data-card:hover {
            transform: translateY(-3px);
        }

        .data-card.temperature {
            border-left-color: #ef4444;
        }

        .data-card.pressure {
            border-left-color: #3b82f6;
        }

        .data-card.flow {
            border-left-color: #10b981;
        }

        .data-card .icon {
            font-size: 28px;
            margin-bottom: 8px;
        }

        .data-card h3 {
            color: #666;
            font-size: 13px;
            margin-bottom: 10px;
            font-weight: normal;
        }

        .data-card .value {
            font-size: 32px;
            font-weight: bold;
            color: #333;
            margin-bottom: 3px;
        }

        .data-card .unit {
            font-size: 14px;
            color: #999;
        }

        .data-card .status {
            margin-top: 8px;
            padding: 3px 10px;
            border-radius: 12px;
            font-size: 12px;
            display: inline-block;
        }

        .status.normal {
            background: #dcfce7;
            color: #166534;
        }

        .status.warning {
            background: #fef3c7;
            color: #92400e;
        }

        .chart-container {
            background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .chart-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .chart-header h2 {
            font-size: 20px;
            color: #333;
        }

        .time-range {
            display: flex;
            gap: 10px;
        }

        .time-range button {
            padding: 8px 15px;
            border: 1px solid #ddd;
            background: white;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s;
        }

        .time-range button.active {
            background: #3b82f6;
            color: white;
            border-color: #3b82f6;
        }

        .chart-placeholder {
            width: 100%;
            height: 500px;
            background: linear-gradient(to bottom, #f8fafc 0%, #f1f5f9 100%);
            border-radius: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        .chart-lines {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        .chart-line {
            position: absolute;
            width: 100%;
            height: 2px;
            opacity: 0.2;
        }

        .mock-chart {
            width: 90%;
            height: 80%;
            position: relative;
        }

        svg {
            width: 100%;
            height: 100%;
        }

        .legend {
            margin-top: 15px;
            display: flex;
            justify-content: center;
            gap: 30px;
        }

        .legend-item {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .legend-color {
            width: 20px;
            height: 3px;
            border-radius: 2px;
        }

        .footer-info {
            background: white;
            padding: 15px 25px;
            border-radius: 10px;
            margin-top: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            color: #666;
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 顶部标题栏 -->
        <div class="header">
            <div>
                <h1>🏭 工业设备监控 - 仪表盘</h1>
            </div>
            <div class="device-selector">
                <span>当前设备：</span>
                <select>
                    <option>PLC_01 (192.168.1.100)</option>
                    <option>PLC_02 (192.168.1.101)</option>
                    <option>PLC_03 (192.168.1.102)</option>
                </select>
                <span class="status-indicator"></span>
                <span style="color: #10b981; font-weight: bold;">在线</span>
            </div>
        </div>

        <!-- 数据卡片 -->
        <div class="cards-grid">
            <!-- 温度卡片 -->
            <div class="data-card temperature">
                <div class="icon">🌡️</div>
                <h3>设备温度</h3>
                <div class="value">68.5</div>
                <div class="unit">℃</div>
                <div class="status normal">正常</div>
            </div>

            <!-- 压力卡片 -->
            <div class="data-card pressure">
                <div class="icon">💨</div>
                <h3>系统压力</h3>
                <div class="value">320.2</div>
                <div class="unit">kPa</div>
                <div class="status normal">正常</div>
            </div>

            <!-- 流量卡片 -->
            <div class="data-card flow">
                <div class="icon">💧</div>
                <h3>流量</h3>
                <div class="value">45.67</div>
                <div class="unit">L/min</div>
                <div class="status warning">偏高</div>
            </div>
        </div>

        <!-- 实时曲线图 -->
        <div class="chart-container">
            <div class="chart-header">
                <h2>📈 实时数据趋势</h2>
                <div class="time-range">
                    <button>最近1分钟</button>
                    <button class="active">最近5分钟</button>
                    <button>最近15分钟</button>
                    <button>最近1小时</button>
                </div>
            </div>

            <div class="chart-placeholder">
                <div class="mock-chart">
                    <svg viewBox="0 0 800 300" xmlns="http://www.w3.org/2000/svg">
                        <!-- 网格线 -->
                        <line x1="0" y1="60" x2="800" y2="60" stroke="#e5e7eb" stroke-width="1" />
                        <line x1="0" y1="120" x2="800" y2="120" stroke="#e5e7eb" stroke-width="1" />
                        <line x1="0" y1="180" x2="800" y2="180" stroke="#e5e7eb" stroke-width="1" />
                        <line x1="0" y1="240" x2="800" y2="240" stroke="#e5e7eb" stroke-width="1" />

                        <!-- 温度曲线 (红色) -->
                        <polyline points="0,150 100,140 200,145 300,135 400,130 500,140 600,145 700,140 800,138"
                            fill="none" stroke="#ef4444" stroke-width="3" opacity="0.8" />

                        <!-- 压力曲线 (蓝色) -->
                        <polyline points="0,180 100,175 200,178 300,170 400,165 500,172 600,176 700,170 800,168"
                            fill="none" stroke="#3b82f6" stroke-width="3" opacity="0.8" />

                        <!-- 流量曲线 (绿色) -->
                        <polyline points="0,210 100,205 200,208 300,200 400,195 500,203 600,207 700,202 800,200"
                            fill="none" stroke="#10b981" stroke-width="3" opacity="0.8" />
                    </svg>
                </div>
            </div>

            <div class="legend">
                <div class="legend-item">
                    <div class="legend-color" style="background: #ef4444;"></div>
                    <span>温度 (℃)</span>
                </div>
                <div class="legend-item">
                    <div class="legend-color" style="background: #3b82f6;"></div>
                    <span>压力 (kPa)</span>
                </div>
                <div class="legend-item">
                    <div class="legend-color" style="background: #10b981;"></div>
                    <span>流量 (L/min)</span>
                </div>
            </div>
        </div>

        <!-- 底部信息 -->
        <div class="footer-info">
            <div>
                <strong>最后更新：</strong> 2025-10-29 14:32:15
            </div>
            <div>
                <strong>采集周期：</strong> 1秒/次
            </div>
            <div>
                <strong>数据点数：</strong> 300
            </div>
        </div>
    </div>

    <script>
        // 从URL参数中获取设备ID并自动选择
        window.addEventListener('load', function () {
            const urlParams = new URLSearchParams(window.location.search);
            const deviceId = urlParams.get('deviceId');

            if (deviceId) {
                const deviceSelector = document.querySelector('.device-selector select');
                // 将设备ID转换为下拉框索引 (deviceId 1,2,3 对应索引 0,1,2)
                const index = parseInt(deviceId) - 1;
                if (index >= 0 && index < deviceSelector.options.length) {
                    deviceSelector.selectedIndex = index;

                    // 可选：显示提示信息
                    console.log(`已自动选择设备 ${deviceId}: ${deviceSelector.options[index].text}`);
                }
            }
        });

        // 模拟实时数据更新
        setInterval(() => {
            const tempValue = document.querySelector('.temperature .value');
            const newTemp = (68 + Math.random() * 2).toFixed(1);
            tempValue.textContent = newTemp;

            const pressValue = document.querySelector('.pressure .value');
            const newPress = (318 + Math.random() * 5).toFixed(1);
            pressValue.textContent = newPress;

            const flowValue = document.querySelector('.flow .value');
            const newFlow = (45 + Math.random() * 2).toFixed(2);
            flowValue.textContent = newFlow;
        }, 2000);
    </script>
</body>

</html>